/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import BO.Service;
import UI.PMUI;
import UI.UserUI;
import java.io.Serializable;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.http.HttpSession;


public class ListMessagesBean implements Serializable{
    
    private PMUI selected;

    /** Creates a new instance of ListMessagesBean */
    public ListMessagesBean() {
    }
    
    public List<PMUI> getReceivedMessages(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserUI user =(UserUI) session.getAttribute("User");
        
        
                
        return Service.getReceivedPrivateMessages(user);
                
        
    }
    
    public List<PMUI> getSentMessages(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        UserUI user =(UserUI) session.getAttribute("User");
        
        
                
        return Service.getSentPrivateMessages(user);
                
        
    }
    
    public PMUI getSelected() {
        return selected;
    }

    public void setSelected(PMUI selected) {
        this.selected = selected;
    }

    public void selectionListener(ActionEvent event) {
        this.selected = (PMUI) event.getComponent().getAttributes().get("selection");
        FacesContext context = FacesContext.getCurrentInstance();
        ReadMessageBean readMessageBean = (ReadMessageBean) context.getApplication().evaluateExpressionGet(context, "#{readMessageBean}", ReadMessageBean.class);
        readMessageBean.setSelected(selected);
    }
    
    public String goToDetails(){
        return "go";
    }
}
